home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2001 May / SGI Freeware 2001 May - Disc 1.iso / dist / fw_mysql.idb / usr / freeware / bin / mysql_install_db.z / mysql_install_db
Text File  |  1999-10-18  |  11KB  |  318 lines

  1. #!/bin/sh
  2. # Copyright (C) 1997, 1998 TCX DataKonsult AB & Monty Program KB & Detron HB
  3. # For a more info consult the file COPYRIGHT distributed with this file
  4.  
  5. # This scripts creates the privilege tables db, host, user, tables_priv,
  6. # columns_priv in the mysql database, as well as the func table.
  7. #
  8. # All arguments (exept -IN-RPM as a first argument) to this script are
  9. # passed to mysqld
  10.  
  11. ldata=/var/spool/mysql
  12. mdata=$ldata/mysql
  13. execdir=/usr/freeware/sbin
  14. bindir=/usr/freeware/bin
  15. force=0
  16. IN_RPM=0
  17.  
  18. # Are we doing an rpm install?
  19. if test "$1" = "-IN-RPM"; then IN_RPM=1; shift; fi
  20. if test "$1" = "--force"; then force=1; shift; fi
  21.  
  22. # Get mysqld/safe_mysqld options from /etc/my.cnf or ~/.my.cnf
  23. if test -w /
  24. then
  25.   conf=/etc/my.cnf
  26. else
  27.   conf=$HOME/.my.cnf
  28. fi
  29.  
  30. if test -f "$conf"
  31. then
  32.   if grep "^datadir" $conf >/dev/null
  33.   then
  34.     ldata=`grep "^datadir" $conf | cut -f 2 -d=`
  35.   fi
  36.   if grep "^execdir" $conf >/dev/null
  37.   then
  38.     ldata=`grep "^execdir" $conf | cut -f 2 -d=`
  39.   fi
  40.   if grep "^bindir" $conf >/dev/null
  41.   then
  42.     ldata=`grep "^bindir" $conf | cut -f 2 -d=`
  43.   fi
  44.   if grep "^user" $conf >/dev/null
  45.   then
  46.     user=`grep "^user" $conf | cut -f 2 -d=`
  47.   fi
  48. fi
  49.  
  50. if test ! -x $execdir/mysqld
  51. then
  52.   if test "$IN_RPM" -eq 1
  53.   then
  54.     echo "FATAL ERROR $execdir/mysqld not found!"
  55.     exit 1
  56.   else
  57.     echo "Didn't find $execdir/mysqld"
  58.     echo "You should do a 'make install' before executing this script"
  59.     exit 1
  60.   fi
  61. fi
  62.  
  63. # On IRIX hostname is in /usr/bsd so add this to the path
  64. PATH=$PATH:/usr/bsd
  65. hostname=`hostname`        # Install this too in the user table
  66.  
  67. # Check if hostname is valid
  68. if test "$IN_RPM" -eq 0 -a $force -eq 0
  69. then
  70.   resolved=`$bindir/resolveip $hostname 2>&1`
  71.   if [ $? -ne 0 ]
  72.   then
  73.     resolved=`$bindir/resolveip localhost 2>&1`
  74.     if [ $? -eq 0 ]
  75.     then
  76.       echo "Sorry, the host '$hostname' could not be looked up."
  77.       echo "Please configure the 'hostname' command to return a correct hostname."
  78.       echo "If you want to solve this at a later stage, restart this script with"
  79.       echo "the --force option"
  80.       exit 1
  81.     fi
  82.     echo "WARNING: Your libc libraries are not 100 % compatible with this MySQL version"
  83.     echo "mysqld should work normally with the exception that host name resolving"
  84.     echo "will not work.  This means that you should use IP addresses instead"
  85.     echo "of hostnames when specifying MySQL privileges !"
  86.   fi
  87. fi
  88.  
  89. # Create database directories mysql & test
  90. if test "$IN_RPM" -eq 0
  91. then
  92.   if test ! -d $ldata; then mkdir $ldata; fi
  93.   if test ! -d $ldata/mysql; then mkdir $ldata/mysql; fi
  94.   if test ! -d $ldata/test; then mkdir $ldata/test; fi
  95.   if test -w / -a ! -z "$user"; then
  96.     chown $user $ldata $ldata/mysql $ldata/test;
  97.   fi
  98. fi
  99.  
  100. # Initialize variables
  101. c_d="" i_d=""
  102. c_h="" i_h=""
  103. c_u="" i_u=""
  104. c_f="" i_f=""
  105. c_t="" c_c=""
  106.  
  107. # Check for old tables
  108. if test ! -f $mdata/db.frm
  109. then
  110.   echo "Creating db table"
  111.  
  112.   # mysqld --bootstrap wants one command/line
  113.   c_d="$c_d CREATE TABLE db ("
  114.   c_d="$c_d   Host char(60) DEFAULT '' NOT NULL,"
  115.   c_d="$c_d   Db char(32) DEFAULT '' NOT NULL,"
  116.   c_d="$c_d   User char(16) DEFAULT '' NOT NULL,"
  117.   c_d="$c_d   Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  118.   c_d="$c_d   Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  119.   c_d="$c_d   Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  120.   c_d="$c_d   Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  121.   c_d="$c_d   Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  122.   c_d="$c_d   Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  123.   c_d="$c_d   Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  124.   c_d="$c_d   References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  125.   c_d="$c_d   Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  126.   c_d="$c_d   Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  127.   c_d="$c_d PRIMARY KEY Host (Host,Db,User),"
  128.   c_d="$c_d KEY User (User)"
  129.   c_d="$c_d );"
  130.   
  131.   i_d="INSERT INTO db VALUES ('%','test','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  132.   INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');"
  133. fi
  134.  
  135. if test ! -f $mdata/host.frm
  136. then
  137.   echo "Creating host table"
  138.  
  139.   c_h="$c_h CREATE TABLE host ("
  140.   c_h="$c_h  Host char(60) DEFAULT '' NOT NULL,"
  141.   c_h="$c_h  Db char(32) DEFAULT '' NOT NULL,"
  142.   c_h="$c_h  Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  143.   c_h="$c_h  Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  144.   c_h="$c_h  Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  145.   c_h="$c_h  Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  146.   c_h="$c_h  Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  147.   c_h="$c_h  Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  148.   c_h="$c_h  Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  149.   c_h="$c_h  References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  150.   c_h="$c_h  Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  151.   c_h="$c_h  Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  152.   c_h="$c_h  PRIMARY KEY Host (Host,Db)"
  153.   c_h="$c_h );"
  154. fi
  155.  
  156. if test ! -f $mdata/user.frm
  157. then
  158.   echo "Creating user table"
  159.  
  160.   c_u="$c_u CREATE TABLE user ("
  161.   c_u="$c_u   Host char(60) DEFAULT '' NOT NULL,"
  162.   c_u="$c_u   User char(16) DEFAULT '' NOT NULL,"
  163.   c_u="$c_u   Password char(16) DEFAULT '' NOT NULL,"
  164.   c_u="$c_u   Select_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  165.   c_u="$c_u   Insert_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  166.   c_u="$c_u   Update_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  167.   c_u="$c_u   Delete_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  168.   c_u="$c_u   Create_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  169.   c_u="$c_u   Drop_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  170.   c_u="$c_u   Reload_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  171.   c_u="$c_u   Shutdown_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  172.   c_u="$c_u   Process_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  173.   c_u="$c_u   File_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  174.   c_u="$c_u   Grant_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  175.   c_u="$c_u   References_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  176.   c_u="$c_u   Index_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  177.   c_u="$c_u   Alter_priv enum('N','Y') DEFAULT 'N' NOT NULL,"
  178.   c_u="$c_u   PRIMARY KEY Host (Host,User)"
  179.   c_u="$c_u );"
  180.  
  181.   i_u="INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  182.   INSERT INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  183.   
  184.   REPLACE INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  185.   REPLACE INTO user VALUES ('$hostname','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y');
  186.   
  187.   INSERT INTO user VALUES ('localhost','','','N','N','N','N','N','N','N','N','N','N','N','Y','Y','Y');
  188.   INSERT INTO user VALUES ('$hostname','','','N','N','N','N','N','N','N','N','N','N','N','Y','Y','Y');"
  189. fi
  190.  
  191. if test ! -f $mdata/func.frm
  192. then
  193.   echo "Creating func table"
  194.  
  195.   c_f="$c_f CREATE TABLE func ("
  196.   c_f="$c_f   name char(64) DEFAULT '' NOT NULL,"
  197.   c_f="$c_f   ret tinyint(1) DEFAULT '0' NOT NULL,"
  198.   c_f="$c_f   dl char(128) DEFAULT '' NOT NULL,"
  199.   c_f="$c_f   type enum ('function','aggregate') NOT NULL,"
  200.   c_f="$c_f   PRIMARY KEY (name)"
  201.   c_f="$c_f );"
  202. fi
  203.  
  204. if test ! -f $mdata/tables_priv.frm
  205. then
  206.   echo "Creating tables_priv table"
  207.  
  208.   c_t="$c_t CREATE TABLE tables_priv ("
  209.   c_t="$c_t   Host char(60) DEFAULT '' NOT NULL,"
  210.   c_t="$c_t   Db char(60) DEFAULT '' NOT NULL,"
  211.   c_t="$c_t   User char(16) DEFAULT '' NOT NULL,"
  212.   c_t="$c_t   Table_name char(60) DEFAULT '' NOT NULL,"
  213.   c_t="$c_t   Grantor char(77) DEFAULT '' NOT NULL,"
  214.   c_t="$c_t   Timestamp timestamp(14),"
  215.   c_t="$c_t   Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter') DEFAULT '' NOT NULL,"
  216.   c_t="$c_t   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
  217.   c_t="$c_t   PRIMARY KEY (Host,Db,User,Table_name),"
  218.   c_t="$c_t   KEY Grantor (Grantor)"
  219.   c_t="$c_t );"
  220. fi
  221.  
  222. if test ! -f $mdata/columns_priv.frm
  223. then
  224.   echo "Creating columns_priv table"
  225.  
  226.   c_c="$c_c CREATE TABLE columns_priv ("
  227.   c_c="$c_c   Host char(60) DEFAULT '' NOT NULL,"
  228.   c_c="$c_c   Db char(60) DEFAULT '' NOT NULL,"
  229.   c_c="$c_c   User char(16) DEFAULT '' NOT NULL,"
  230.   c_c="$c_c   Table_name char(60) DEFAULT '' NOT NULL,"
  231.   c_c="$c_c   Column_name char(60) DEFAULT '' NOT NULL,"
  232.   c_c="$c_c   Timestamp timestamp(14),"
  233.   c_c="$c_c   Column_priv set('Select','Insert','Update','References') DEFAULT '' NOT NULL,"
  234.   c_c="$c_c   PRIMARY KEY (Host,Db,User,Table_name,Column_name)"
  235.   c_c="$c_c );"
  236. fi
  237.  
  238.  if $execdir/mysqld --bootstrap --skip-grant-tables \
  239.     --basedir=/usr/freeware --datadir=$ldata "$@" << END_OF_DATA
  240. use mysql;
  241. $c_d
  242. $i_d
  243.  
  244. $c_h
  245. $i_h
  246.  
  247. $c_u
  248. $i_u
  249.  
  250. $c_f
  251. $i_f
  252.  
  253. $c_t
  254. $c_c
  255. END_OF_DATA
  256. then
  257.   echo ""
  258.   if test "$IN_RPM" -eq 0
  259.   then
  260.     echo "To start mysqld at boot time you have to copy support-files/mysql.server"
  261.     echo "to the right place for your system"
  262.     echo
  263.   fi
  264.   echo "PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !"
  265.   echo "This is done with:"
  266.   echo "$bindir/mysqladmin -u root password 'new-password'"
  267.   echo "See the manual for more instructions."
  268.   #
  269.   # Print message about upgrading unless we have created a new db table.
  270.   if test -z "$c_d"
  271.   then
  272.     echo
  273.     echo "NOTE:  If you are upgrading from a MySQL <= 3.22.10 you should run"
  274.     echo "the $bindir/mysql_fix_privilege_tables. Otherwise you will not be"
  275.     echo "able to use the new GRANT command!"
  276.   fi
  277.   echo
  278.   if test -z "$IN_RPM"
  279.   then
  280.     echo "You can start the MySQL demon with:"
  281.     echo "cd /usr/freeware ; $bindir/safe_mysqld &"
  282.     echo
  283.     echo "You can test the MySQL demon with the benchmarks in the 'sql-bench' directory:"
  284.     echo "cd sql-bench ; run-all-tests"
  285.     echo
  286.   fi
  287.   echo "Please report any problems with the /usr/freeware/bin/mysqlbug script!"
  288.   echo
  289.   echo "The latest information about MySQL is available on the web at http://www.mysql.com"
  290.   echo "Support MySQL by buying support/licenses at http://www.tcx.se/license.htmy."
  291.   echo 
  292.   exit 0
  293. else
  294.   echo "Installation of grant tables failed!"
  295.   echo
  296.   echo "Examine the logs in $ldata for more information."
  297.   echo "You can also try to start the mysqld demon with:"
  298.   echo "$execdir/mysqld --skip-grant &"
  299.   echo "You can use the command line tool"
  300.   echo "$bindir/mysql to connect to the mysql"
  301.   echo "database and look at the grant tables:"
  302.   echo
  303.   echo "shell> $bindir/mysql -u root mysql"
  304.   echo "mysql> show tables"
  305.   echo
  306.   echo "Try 'mysqld --help' if you have problems with paths. Using --log"
  307.   echo "gives you a log in $ldata that may be helpful."
  308.   echo
  309.   echo "The latest information about MySQL is available on the web at"
  310.   echo "http://www.mysql.com"
  311.   echo "Please consult the MySQL manual section: 'Problems running mysql_install_db',"
  312.   echo "and the manual section that describes problems on your OS."
  313.   echo "Another information source is the MySQL email archive."
  314.   echo "Please check all of the above before mailing us!"
  315.   echo "And if you do mail us, you MUST use the /usr/freeware/bin/mysqlbug script!"
  316.   exit 1
  317. fi
  318.